package com.platform.qujia.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.parser.Feature;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.UUID;

/**
 * 随行付，公共方法
 */
public class SXFPaySign {
    //合作方私钥(替换成自己的)
    // public static final String privateKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDM+4PMi2ZPqpeCQ1IIV8mWYmGubr3DoEEJ3W2oEu8bFMVVpK5Jx6WhQ9xR83OQW7lbMI+BbumilKXfHdHrW7gWvu7yB2dD50GbT6bZXXnuddui+BnS/Yc9QxFS+HLcOX8bsmgJ5P/4D1Klm4k3OOsGJ3CsLDuz8RwNlxwuhg8+lQIDAQAB";
    //测试环境私钥
    //public static final String privateKey = "MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAMz7g8yLZk+ql4JDUghXyZZiYa5uvcOgQQndbagS7xsUxVWkrknHpaFD3FHzc5BbuVswj4Fu6aKUpd8d0etbuBa+7vIHZ0PnQZtPptldee5126L4GdL9hz1DEVL4ctw5fxuyaAnk//gPUqWbiTc46wYncKwsO7PxHA2XHC6GDz6VAgMBAAECgYEAgC2C1CQTPRvqk+0u3cKvbtdkR6Q+C5cpNFb/XAtC80dAwnYw+jfarYX2vlQi3pFMzeYGxqQpep3DP0qxWqBG8uu7Depw2HlWcw+6z68G3Vpkprx9FHnsy/ijCX/76HMmDmGN1r68FnDZXHKdaLZPQeNxDY3Hz83Quq04yav5Ah0CQQDoVoZZM6SyF+gz4/mg29UwkEXcn5uUARWo7QrO6vOsYzTEiNvNIlLFxd5xE2i9LAKKLWBtuaMovrdC4fHguQaLAkEA4dvINHcuehDHVzgS5I/6hB5PnQZOrnZFDZUd7woh9xUu9qQTxZpPcbfSpDFCKDbTknM1dn+7WpLk6Zd9YGyTXwJACXu2oh90gnxtUujkQIeYjRHmeBnfrMvaiXmbblSyu3+VIMyBRD85Z68q5CyposcQF3nArNnd6gTW0BkO2WBT/wJAUUGbA5UlOXEz5mMcGPLbtBCbn+iXAhk2uq49OLSyh4wtezqIinz7u/PgaoX2QTWIZJXiVCGcK/fRN2DzEG+/jQJAIQQFJNUX5i7aUS4By8xrffUpeTTiszu+WTU5Rz2jRoT8YwgqiqAWG9dNSggcfnJIz968a+Jg5s483y06mEEmjA==";
    //生产环境私钥
//    public static final String privateKey="MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAPCpA8iF1tYerDYcZTGiPkRHlQKlkM2vy752cLZydVUrfKkGQaSMBHbmgK7LgenQ6cjWl2mM5zLOWxqNKxsUj/xMbkAdYXKtYy1nL6NLo3RI+cXbUB5tNiS4ojSwjFg4AHIfjGyBnnQar/dulfuNJ3QBsfHBDR/DsIfXUaBcmsoFAgMBAAECgYEA8A7YHEUNWUb9Z3iJpKn/TKLOy/YVbGdoaFPC+OtRiSS40+3OuvGEXoptYG7V50MigNk17e7EjNR04hZhIkEvoX/d9KLIKRtZUOMga6GhqD/PqRpgKq8JObMkvJ1U7KeEimUqBeukbvzBUJrVQT1RpbXmX3zpf0kj7l/FPOfZD8ECQQD9RpXw7gtv96N6WIF2k42UMAMLVuGivTW2bZzxP6TCD/FeZMG2JNy3nydCc2v6GuGDQZ8WCQIpzK72gMzLrYVVAkEA8z+w+Ao8Y6BxX8P/5GZg4x1ZHqQOfsrWbC6iMeIenLkAgMpEPYLYpm5nZ0db7pf5OU037bSXxQoauQnjOM8x8QJBANzQGk94Kg6PFz7GRPDNScTlavIK6CMK1PZccFTASPNMFQJX067qSmfoYMEFgiEGKJBXuMvsRK+OnQeaWXJFsRUCQFva9Uz1MJC+iZGMRhlNv9CDyJ+VfBPNLON1SLJlnQG5qsL3noVL39wZXNrXS5Pxt5831aLhy14Qzr6JSVCujUECQQDD0KIfodS9dxKnstJaaX2B5aYXPYsI+4PBMeFw4inl+9JFJb85U1SmuYAkGPj8OFBtxkhzeHXkvD5aMKj0cUVs";
    public static final String privateKey="MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCjpAs/ZC8J+rL0 \n" +
            "vAFXvXmRCjga4pzLP5t/8TbmR3CeS3heYtw9ahE4gwkkqdwE9J7FoIUTkd9M/2v3 \n" +
            "k6aO4zQjtPj42zw6yX0XaJJpTF2MTagKZ8g1Sk9tLOE+tDjbfb6KFXe424ia6YcR \n" +
            "C6gPdtfYMp508PH7+2HyYJneNjouJruQePibiQQ4gCrP6/hvyzQHDXO4h5kUbNIC \n" +
            "0gcf0OgDqX2VpcRZv0mp/eu/2aC6O1qbJUkIJKPOzRMzapUEYAmuKN+XrGiTRkFB \n" +
            "WF2LGWTesKWqeqV1IgbnMxXV6IvgZbVMTZ12OR1TuCcyf1MI84ONQ1/7JVUBGbJc \n" +
            "iEqRVlmXAgMBAAECggEAWXHbLAUoqP29P4Rb/4dzoVHCpP9k0Lut1VsVtP0rk3qR \n" +
            "CpZi57bIPulw3/dwac0D0+YPl0jOk5mxfBvamJOb9kB/Lhc3brKfi2H/VUsGfyAb \n" +
            "T8S2bFp326cCX3HG+kJbGcLuM77bhkFLMIf8jqdZB7VzY1woCKG5QfCHaiyd1Ic7 \n" +
            "Qj2dwiVFwNkFrZGcwCnvgZdlt2UyPoKWIyOEicU4XDCTwGLcBlRKmSQrvn95q0hV \n" +
            "8+p8dwJxOrmXYi39JVjDQLkfk/+EfHvlHoxuMGwHvpaVPMHzzLfwssBG8ZMIiYcP \n" +
            "OaIEU8UdXtwYarRa56YIEyuM5dQ0kaF4tsQtTt8/EQKBgQDXyFoeeeJ0raLGncFY \n" +
            "FuZHSY/osDLhA8mWsxRZ3O9FtvXfmFiKGOfBIb5R0DgksJ3bnt3cPeH8HtHb9W// \n" +
            "zDTJAaiKEp6CYlZqjfZfbiZvdNFkADN3RvwblByT6WinveufjDB0NJ7GUkjcsa0f \n" +
            "Je6iHnyHrzLfL/JYXL6Q5BR4gwKBgQDCI9iWlb6S0I0pYGFoopkIKEfK34v6V94S \n" +
            "JmE36Et1Jw/OhW/mMDPm05SuOijWRwggYQbGhkM5nAlvurBWDLDNF0Q69J3liJ78 \n" +
            "kt6iu4byMXhSAbL82cdu3xRv7h1l5VW0RJmjY/s1fSwP+33R+v7vzYNA2oZug7br \n" +
            "0+5X2UaGXQKBgAU40gV+yZ4tPY008CLjmvsKqrLk4LZVUyGUf9+U2y2CufyJQUtG \n" +
            "QwWHfYWZVmJ867UO6SuVS8zAKi/6hpVYKcbbhWqh/LgHDTRS7y1sCv4Tg6W544T1 \n" +
            "cNByCycBNQkqLXOU/u8w/s6p2x2MJzZjwpylxDm8YazJCkJdLDdxbZVlAoGAO2x1 \n" +
            "c0JKnu2vB6c0qa57YP/TWcmrMumKU8vjnhVAY4+dSv2VDsRaXqEMtXef4FbFqgOI \n" +
            "62NVWGDmkoh2SSCBTYV9oP4XBpcW8wCRnQYBfEigJ5nVi4etf8ZQnyInZXUZEqCc \n" +
            "1mJYFjtGLW4xSQCm4Afr0QISe+ldKDoqjkE3URECgYBZchQGPb8PY/GMnYp9uM+o \n" +
            "syhX8y02dXjRMFc01JwxUGWhp/WzRsDfjv2YSLm/ZfWkV3piLhEXPU6U8zp8Kp7b \n" +
            "utH1e8atjs9Vw2LqDYMHWFfBpIvLg1zvRNvS5smpkBIlhxupWUumLfgaSNGbYCbL \n" +
            "pZ6z8qNgOrK3LV9kfHuBzg== ";


//随行付公户私钥
    public static final String privateTestKey="MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALgMi6P6ad2kANoZPU/GItj9x8RXGZWDBFkIartrOFglrufBLBOb27EByDyfthc6bhcIA3VcdtImk+uWcpxecI8tSf+mUSsc0ecEIJF9P81Uz5oTphwS9M01HOVXNog1N7R6kr/BqabxfhCfzmAwd/+fioRspS9COXbHcsppwP0vAgMBAAECgYBWau2WTRowS7VqsrcrIely4ZZPBmao4R/FfkI/RhTqrqb1gqpjeqco8aFHdeZV+cV/Yu/cx1GzUxHZaIbgDSfkBmuA/vRvklserIXg+bf56Z5f3eAo3Ya0X2rymOcSASaCt5rjCj/xGNVK9X2dTWbTUPYFD/LwUNSp9kdwAChXAQJBAOHVjwhf+tKdbQBY4lrCwOqZ/DlupItfd2Ht+GCvOU20buCfndI9539U5UCfpZxz5+aUYl5G7ew3PyT+0qGCIqECQQDQoiJUOL8Xb2bRILiOMr53hJIR/RwJgBa2zb1x1tlvR1dSBlg73dww2fjNBnC+pIxkuesIaV4W1zvFDKg4Yt3PAkBAaSy2csmTMJtaMf+9azaisvChYNFFfyEJqVniGZf6da/6GQxmXomcY5ZPbDlL+jL2LPQxd4F8kfVMk/F3ZyqBAkBb4JrXlinpKyEPRaag0I36WkJtc5auRF88X7xm7qPQko1MzQh8TMbUKJmdyJFME3DURt/PU3+g9WYX7+wA8OEXAkEAs5ZTPjS8xWvCDo0DJ3z7m8hSgiF3gECHUJEjeVbEQgpFJLPMfLmgnk6xLa4Lw5q/eAHqzBlNWYFDEvmGHpjMgw==";


    // 测试环境随行付公钥
    public static final String sxfTestPublic = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCOmsrFtFPTnEzfpJ/hDl5RODBxw4i9Ex3NmmG/N7A1+by032zZZgLLpdNh8y5otjFY0E37Nyr4FGKFRSSuDiTk8vfx3pv6ImS1Rxjjg4qdVHIfqhCeB0Z2ZPuBD3Gbj8hHFEtXZq8+msAFu/5ZQjiVhgs5WWBjh54LYWSum+d9+wIDAQAB";
   //生产环境随行付公钥
    public static final String sxfPublic = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjo1+KBcvwDSIo+nMYLeOJ19Ju4ii0xH66ZxFd869EWFWk/EJa3xIA2+4qGf/Ic7m7zi/NHuCnfUtUDmUdP0JfaZiYwn+1Ek7tYAOc1+1GxhzcexSJLyJlR2JLMfEM+rZooW4Ei7q3a8jdTWUNoak/bVPXnLEVLrbIguXABERQ0Ze0X9Fs0y/zkQFg8UjxUN88g2CRfMC6LldHm7UBo+d+WlpOYH7u0OTzoLLiP/04N1cfTgjjtqTBI7qkOGxYs6aBZHG1DJ6WdP+5w+ho91sBTVajsCxAaMoExWQM2ipf/1qGdsWmkZScPflBqg7m0olOD87ymAVP/3Tcbvi34bDfwIDAQAB";
    /**
     * 封装传参信息，增加公共信息，增加业务信息
     * @param reqData
     * @return
     */
    public static String getSXFPay(JSONObject reqData ) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        String dataStr = df.format(new Date());
        ApiRequestBean<JSONObject> reqBean = new ApiRequestBean<JSONObject>();
        //reqBean.setOrgId("77563944");//测试 合作机构id
//        reqBean.setOrgId("73153713");//生产合作机构id
        reqBean.setOrgId("92346959");//生产合作机构id
        reqBean.setReqId(UUID.randomUUID().toString().replaceAll("-", ""));//请求id 订单号
        reqBean.setSignType("RSA");//签名类型
        reqBean.setTimestamp(dataStr);//请求时间
        reqBean.setVersion("1.0");//版本
        //将业务参数存放在 JSON 对象中
        reqBean.setReqData(reqData);
        String req = JSONObject.toJSONString(reqBean);
        return req;
    }


    /**
     *封装组织加密串
     */
    public static String getSignContent(String req){
        System.out.println("req:" + req);
        //此处不要改变reqData里面值的顺序用LinkedHashMap
        HashMap reqMap = JSON.parseObject(req, LinkedHashMap.class, Feature.OrderedField);
        //组装加密串
        String signContent = RSASignature.getOrderContent(reqMap);
        return "";
    }

}
